package com.squid.user.controller;

import com.squid.base.common.annotation.format.FormatValid;
import com.squid.base.common.bean.PageReq;
import com.squid.base.common.bean.PageResp;
import com.squid.base.common.bean.Return;
import com.squid.user.model.req.UserEntityRegisterReq;
import com.squid.user.model.req.UserEntitySelectReq;
import com.squid.user.model.req.UserEntityUpdateReq;
import com.squid.user.model.resp.UserEntitySelectResp;
import com.squid.user.service.user.UserEntityService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * Description
 *
 * @author jinhang
 * @since 2024-2-7
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    UserEntityService userEntityService;

    @PostMapping("/register")
    @FormatValid(phone = true, idCard = true)
    public Return<Object> register(@RequestBody @Valid UserEntityRegisterReq req) {
        userEntityService.register(req);
        return Return.success();
    }

    @PostMapping("/updateInfo")
    public Return<Object> updateInfo(@RequestBody UserEntityUpdateReq req) {
        userEntityService.updateInfo(req);
        return Return.success();
    }

    @PostMapping("/pageInfo")
    public Return<PageResp<UserEntitySelectResp>> pageInfo(@RequestBody PageReq<UserEntitySelectReq> req){
        PageResp<UserEntitySelectResp> response = userEntityService.pageInfo(req);
        return Return.<PageResp<UserEntitySelectResp>>success().data(response);
    }

}
